import base64
import os
from dashscope import MultiModalConversation

#  Base64 编码格式
def encode_video(video_path):
    with open(video_path, "rb") as video_file:
        return base64.b64encode(video_file.read()).decode("utf-8")

# 将xxxx/test.mp4替换为你本地视频的绝对路径
base64_video = encode_video("C:\\Users\\Administrator\\Pictures\\2025-05-28-10-37.mp4")

messages = [{'role': 'system',
                'content': [{'text': 'You are a helpful assistant.'}]},
                {'role':'user',
                # fps参数控制视频抽帧数量，表示每隔1/fps 秒抽取一帧
                'content': [{'video': f"data:video/mp4;base64,{base64_video}","fps":2},
                            {'text': '描述视频的内容'}]}]
response = MultiModalConversation.call(
    # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx"
    api_key='sk-ad76a80e1feb400b9b7e505b597b3892',
    model='qwen-vl-max',
    messages=messages)

print(response["output"])